// import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { JurisdictionData, LoginData } from '@/interfaces/RequestType'

export const useUserStore = defineStore('user', () => {
  // 变量
  const user = ref<LoginData | null>(null) // 用户信息
  const jurisdiction = ref<JurisdictionData[] | null>(null) // 用于权限
  const currentRouteMenu = ref('') // 当前菜单路由

  // 函数

  // 设置user
  const setUser = (newUser: LoginData | null) => {
    user.value = newUser
  }
  // 设置jurisdiction
  const setJurisdiction = (newJurisdiction: JurisdictionData[] | null) => {
    jurisdiction.value = newJurisdiction
  }
  // 设置currentRouteMenu
  const setCurrentRouteMenu = (newMenu: string) => {
    currentRouteMenu.value = newMenu
  }

  // 导出
  return {
    user,
    setUser,
    jurisdiction,
    setJurisdiction,
    currentRouteMenu,
    setCurrentRouteMenu
  }
}, {
  persist: {
    storage: sessionStorage,
    key: 'user', // 以什么名字存入本地存储中
    pick: ['user', 'jurisdiction', 'currentRouteMenu'],
  },
})
